import 'dart:math';

import 'package:flutter/cupertino.dart';

import '../../flutter_public.dart';

/// FileName bottom_edge_insets
///
/// @Author lax
/// @Date 2025/4/17
///
/// @Description

class BottomEdgeInsets extends EdgeInsets {
  static double defaultBottom = 16;

  static double safeTop({BuildContext? context, double value = 0}) {
    context ??= FlutterPublic.navigatorKey?.currentContext;
    if (context != null) {
      return MediaQuery.of(context).padding.top + value;
    }
    return value;
  }

  static double safeBottom({BuildContext? context, double value = 0}) {
    return max(defaultBottom, value);
  }

  BottomEdgeInsets.zero({
    BuildContext? context,
    bool isSafeTop = false,
    bool isSafeBottom = true,
  }) : super.only(
          top: isSafeTop ? BottomEdgeInsets.safeTop(context: context) : 0,
          bottom:
              isSafeBottom ? BottomEdgeInsets.safeBottom(context: context) : 0,
        );

  BottomEdgeInsets.all(
    double value, {
    BuildContext? context,
    bool isSafeTop = false,
    bool isSafeBottom = true,
  }) : super.only(
          top: isSafeTop
              ? BottomEdgeInsets.safeTop(context: context, value: value)
              : value,
          left: value,
          right: value,
          bottom: isSafeBottom
              ? BottomEdgeInsets.safeBottom(context: context, value: value)
              : 0,
        );

  BottomEdgeInsets.symmetric({
    double horizontal = 0,
    double vertical = 0,
    BuildContext? context,
    bool isSafeTop = false,
    bool isSafeBottom = true,
  }) : super.only(
          top: isSafeTop
              ? BottomEdgeInsets.safeTop(context: context, value: vertical)
              : vertical,
          left: horizontal,
          right: horizontal,
          bottom: isSafeBottom
              ? BottomEdgeInsets.safeBottom(context: context, value: vertical)
              : 0,
        );

  BottomEdgeInsets.only({
    double top = 0,
    double left = 0,
    double right = 0,
    double bottom = 0,
    BuildContext? context,
    bool isSafeTop = false,
    bool isSafeBottom = true,
  }) : super.only(
          top: isSafeTop
              ? BottomEdgeInsets.safeTop(context: context, value: top)
              : top,
          left: left,
          right: right,
          bottom: isSafeBottom
              ? BottomEdgeInsets.safeBottom(context: context, value: bottom)
              : 0,
        );
}
